/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package settings.collections;


import settings.collections.elements.SettingsManager;
import settings.collections.elements.Schleife;
import java.util.ArrayList;

/**
 *
 * @author rbs
 */
public class SchleifenCollection extends SettingsManager{
    private ArrayList<Schleife> schleifen;

    public SchleifenCollection() {
        super("schleifen");
        schleifen = new ArrayList<Schleife>();
    }
    
    
    public void addschleife(Schleife schleife)
    {
        schleifen.add(schleife);
    }
    
    public Schleife getSchleife(int id)
    {
        for (Schleife schleife: schleifen)
            if (schleife.getId() == id)
                return schleife;
        return null;    
    }
    
    public Boolean delSchleife(int id)
    {
        
        Schleife schleife = getSchleife(id);
        
        if (schleife != null)
        {
            schleifen.remove(schleife);
            for (Schleife schleife2: schleifen)
                if (schleife2.getId() > id)
                    schleife2.setId(schleife2.getId() - 1);

            return true;
        }
        else
            return false; 
    }
    
    public void changeSchleife(Schleife old_schleife, Schleife new_schleife)
    {
        schleifen.set(old_schleife.getId(), new_schleife);
        System.out.println("Schleife Changed: " + new_schleife.getId() + " " + new_schleife.getName());
    }
    
    public ArrayList<Schleife> getSchleifen()
    {
        return schleifen;
    }
    
    //DEBUG
    public void printAllSchleifen()
    {
        System.out.println("Schleifen remainig");
        for (Schleife schleife: schleifen)
            System.out.println(schleife.getId() + "|" + schleife.getName() + "|" + schleife.getRic());
    }
    
}
